package com.heyue.demo.thread;

/**
 * @author fenghe
 * @date 2022/2/10 8:15
 */
public class AtomicWrongDemo {
    private int val = 0;

    public static void main(String[] args) {
        AtomicWrongDemo atomicWrongDemo = new AtomicWrongDemo();

        for (int i = 0; i < 10; ++i) {
            new Thread(atomicWrongDemo::increase).start();
        }

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(atomicWrongDemo.getVal());
    }

    private void increase() {
        for (int i = 0; i < 1000; ++i) {
            ++this.val;
        }
    }

    private int getVal() {
        return this.val;
    }
}
